class Houses:
    def __init__(self, name, total_area, free_area=None, item_list=None):
        self.nm = name
        self.ta = total_area
        if free_area is None:
            self.fa = free_area = self.ta = total_area
        self.fa = free_area
        if item_list is None:
            item_list = []
        # else:
        #     for x in item_list:
        #         self.fa -= x.oa
        self.il = item_list

    def __str__(self):
        return f'这栋房子的户型是{self.nm}，总面积是{self.ta}平米，剩余面积是{self.fa}平米，家具名称列表是{self.il}。'

    def add_item(self, item_name):
        if self.fa >= item_name.oa:
            self.il.append(item_name.nm)
            self.fa -= item_name.oa
            print(self)
        else:
            print(f'户型为{self.nm}的房子剩余空间不足，仅剩{self.fa}平米，然而现在还想塞入占地{item_name.oa}平米的家具，办不到！')


class HouseItem:
    def __init__(self, name, occ_area):
        self.nm = name
        self.oa = occ_area

    def __str__(self):
        return f'{self.nm}占地{self.oa}平米'


bed = HouseItem('bed', 4)
chest = HouseItem('chest', 2)
table = HouseItem('table', 1.5)
desk = HouseItem('desk', 2)
TV = HouseItem('Television', 0.8)
sofa = HouseItem('sofa', 1.6)
print(bed)
print(chest)
print(table)
print(desk)
print(TV)
print(sofa)
my_house = Houses('A', 150, 100, [desk.nm, TV.nm])
your_house = Houses('C', 10, 2.8)
print(my_house)
print(your_house)
my_house.add_item(bed)
my_house.add_item(chest)
my_house.add_item(table)
your_house.add_item(desk)
your_house.add_item(TV)
